<template>
  <div>
    <div id="slider" class="mui-slider">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<a :class='["mui-control-item",item.id==0?"mui-active":""]' v-for='item in item' :key='item.id'
						@click ='getPiclist(item.id)'>
							{{ item.title }}
						</a>
					</div>
				</div>
			</div>
			<div>
				<ul class="picContainer">
  				<router-link class="picList" v-for="item in piclist" :key='item.id' :to="'/home/piclist/picinfo/' + item.id" tag='li'>
    				<img class="picList-img" v-lazy="item.img">
						<div class="picList-info">
							<div class="picList-info-title">{{ item.title }}</div>
							<div class="picList-info-sub">{{ item.sub }}</div>
						</div>
  				</router-link>
				</ul>
			</div>
  </div>
</template>
<script>
import { Toast } from "mint-ui"
import mui from '../../lib/mui/js/mui.min.js'
mui('.mui-scroll-wrapper').scroll({
	deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
})
export default {
  data(){
    return {
			item:[],
			piclist:[]
		}
  },
  methods:{
		getItem(){
			this.$http.get('home/item').then(result=>{
				// console.log(result)
				if(result.status === 200){
					this.item = result.body.piclist
					var obj = { "id":0,"title":"全部" }
					this.item.unshift(obj)
				}else{
					Toast('获取分类失败！！')
				}
			})
		},
		getPiclist(id){
			this.$http.get('home/item/'+id).then(result=>{
				console.log(result)
				if(result.status === 200){
					if(id == 0){
						this.piclist=[]
						for(var i=0;i < result.body.piclist.length;i++){
							// console.log(result.body.piclist[i])
							// console.log(result.body.piclist[i].neirong)
							this.piclist=this.piclist.concat(result.body.piclist[i].neirong)
						}
					}else{
						this.piclist=[]
						this.piclist = result.body.piclist[id-1].neirong
					}
				}else{
					Toast('获取图片失败！！')
				}
			})
		}
	},
	created(){
		this.getItem();
		this.getPiclist(0)
	},
  mounted(){
    mui('.mui-scroll-wrapper').scroll({
	    deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  }
}
</script>
<style lang="scss" scoped>
*{
  touch-action: pan-y;
}

.picContainer{
	list-style: none;
	margin: 0;
	padding: 0;
	li{
		background:#ccc;
		text-align: center;
		box-shadow: 0 0 6px #999;
		margin: 0 5px 5px 10px;
		position: relative;
		border-radius: 10px;
		overflow: hidden;
		height: 300px;
		img{
			width: 100%;
			vertical-align: middle;
		}
		img[lazy=loading] {
  		width: 40px;
  		height: 300px;
  		margin: auto;
		}
		.picList-info{
			width: 100%;
			position: absolute;
			bottom:0;
			color: #FFF;
			background-color: rgba(0,0,0,0.4);
			.picList-info-title{
				font-size: 14px;
			}
			.picList-info-sub{
				font-size: 10px;
				width: 100%;
				max-height: 60px;
			}
		}

	}
}
</style>
